package org.ecshop.controllers;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;
import org.ecshop.models.Goods;

import will.icecoffe.core.DataAccessException;
import will.icecoffe.core.SimpleDataAccessService;

import com.opensymphony.xwork2.ModelDriven;



public class GoodsController implements ModelDriven<Object> {
	
	private final String domainName = "http://www.xingouwu360.com/";
	
	private int id;
	private Goods goods = new Goods();
	private List<Goods> list;
	
	private String key;
	
	public int getId() {
		return id;
	}

	public void setId(int id) throws DataAccessException {
		this.id = id;
		if(id > 0)
			this.goods = das.find("hql", "findGoodsById", id).get(0);
		this.goods.setGoodsThumb(this.domainName + this.goods.getGoodsThumb());
		this.goods.setGoodsImg(this.domainName + this.goods.getGoodsImg());
		this.goods.setOriginalImg(this.domainName + this.goods.getOriginalImg());
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}


	@Resource(name="DAS")
	private SimpleDataAccessService<Goods> das;
	
	public String index() throws DataAccessException {
		this.list = das.find("hql", "goodsSearch");
		System.out.println(this.list.size());
		for(Goods g : list) {
			g.setGoodsThumb(this.domainName + g.getGoodsThumb());
			g.setGoodsImg(this.domainName + g.getGoodsImg());
			g.setOriginalImg(this.domainName + g.getOriginalImg());
		}
		return null;
	}
	
	public String edit() {
		
		return null;
		
	}
	
	public String editNew() {
		
		return null;
		
	}
	
	public String create() {
		
		return null;
		
	}
	
	public String show() throws DataAccessException {
		//System.out.println(id);
		//System.out.println(this.goods.getGoodsName());
		return null;
	}
	
	
	@Override
	public Object getModel() {
		return (list != null ? list : goods);
	}

}
